#include <tsin/library/TimeoutTrigger.hpp>

#include <tsin/util/Logger.hpp>

#include <cstring>
using namespace std;
using namespace tsin;

TimeoutTrigger::TimeoutTrigger()
        : counter(100000000), timeout(-1)
{
}

TimeoutTrigger::~TimeoutTrigger()
{
}

void TimeoutTrigger::init(int timeout)
{
        this->timeout = timeout;
}

void TimeoutTrigger::reinit()
{
        int arg1 = arguments[0]->getInt();

        switch(nrArguments) {
        case 1:
                if (strcmp(desp, "N") == 0)
                        init(arg1);
                break;
        }
}

bool TimeoutTrigger::trigger()
{
        counter ++;
        if (counter >= timeout) {
                counter = 0;
                return true;
        }

        return false;
}

DynamicObject *bindTimeoutTrigger()
{
        return new TimeoutTrigger;
}
